//https://leetcode.cn/problems/letter-combinations-of-a-phone-number/submissions/
//电话号码字母组合

class Solution {
public:
    void create(const char* digit, string& str)
    {
        if(*digit != '\0')
        {
            int num = *digit - '0';
            for(size_t i = 0; i < strlen(itos[num]); i++)
            {
                str.push_back(itos[num][i]);
                create(digit + 1, str);
                str.pop_back();
            }
        }
        else
        {
            if(!str.empty())
                _ret.push_back(str);
        }
    }

    vector<string> letterCombinations(string digits) {
        string tmp;
        create(digits.c_str(), tmp);
        vector<string> ret;
        swap(ret, _ret);
        return ret;
    }

    vector<string> _ret;
    vector<char*> itos = {"", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
};